package com.example.demo2.common.utils;

import com.example.demo2.common.api.Result;

/**
 * @Author 胡亚伟
 * @Date 2025-06-10
 * @version 1.0
 * @注释
 */

public class ResultGenerator {
	private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

	public static Result<?> genSuccessResult() {
		Result<?> r = new Result<>();
		r.setCode(200);
		r.setMsg(DEFAULT_SUCCESS_MESSAGE);
		return r;
	}

	public static Result<?> genSuccessResult(String message) {
		Result<?> r = new Result<>();
		r.setCode(200);
		r.setMsg(message);
		return r;
	}

	public static <T> Result<T> genSuccessResult(T data) {
		Result<T> r = new Result<T>();
		r.setCode(200);
		r.setMsg(DEFAULT_SUCCESS_MESSAGE);
		r.setResponse(data);
		return r;
	}

	public static <T> Result<T> genSuccessResult(String message, T data) {
		Result<T> r = new Result<T>();
		r.setCode(200);
		r.setMsg(message);
		r.setResponse(data);
		return r;
	}

	public static Result<?> genFailResult(String message) {
		Result<?> r = new Result<>();
		r.setCode(500);
		r.setMsg(message);
		return r;
	}

	public static Result<?> genFailResult(String message, int code) {
		Result<?> r = new Result<>();
		r.setCode(code);
		r.setMsg(message);
		return r;
	}
}
